<template>
  <div class="public-box">
    <div class="public-title">
      公告列表
    </div>
    <div class="public-table">
      <el-table
          :data="tableData"
          border style="width: 99%;margin: 15px auto;max-height: 36vh;height: 36vh"
          empty-text="暂无公告"
      >
        <el-table-column
          type="index"
          width="50"
          align="center"
        />
        <el-table-column
          label="公告标题"
          width="180"
          align="center"
        >
          <template #default="{row}">
            {{ row.file_name }}
          </template>
        </el-table-column>
        <el-table-column
          label="发布时间"
          align="center"
        >
          <template #default="{row}">
            {{computeDate(row.created_at)}}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="more" @click="toRules">
      查看详情 &nbsp;>>
    </div>
  </div>
</template>

<script setup>
import {ElTable, ElTableColumn} from "element-plus"
import {onMounted, ref} from "vue"
import {getrules} from "@/api"
import {useRouter} from "vue-router"

const tableData = ref([])
const router = useRouter()


onMounted(()=>{
  getRulesList()
})

const getRulesList = async () => {
  try {
    const {data:res} = await getrules()
    tableData.value = res.data
  } catch (e) {
    console.log(e)
  }
}

const computeDate = (date) => {
  return date.substring(0,10)
}

const toRules = () => {
  router.push('rule')
}
</script>

<style scoped lang="less">
.public-box{
  width: 56vw;
  height: 47vh;
  max-height: 50vh;
  margin-left: 8.5vw;
  margin-top: 2vh;
  border-radius: 10px;
  box-shadow: 0 0 8px 8px lightgray;
  background-color: #fafafa;
  .public-title{
    height: 5vh;
    border-bottom: 1px solid #e4eaeb;
    box-sizing: border-box;
    line-height: 5vh;
    font-size: 2vh;
    padding-left: 1vw;
    text-align: left;
    font-weight: 600;
  }
  .more{
    height: 2vh;
    text-align: right;
    padding-right: 2vw;
    font-size: 1.5vh;
    vertical-align: top;
    margin-top: -0.5vh;
    width: 5vw;
    color: rgb(72,145,255);
    &:hover{
      color: rgb(72,145,255);
      cursor: pointer;
      text-decoration: underline;
    }
  }
}

.hover{
  &:hover{
    color: #1E90FF;
    text-decoration: underline;
    cursor: pointer
  }
}
</style>
